﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;


namespace ConceptInc.Public.WebPart.UI.WebParts.ListQueryFeature
{
    public class ListQueryWebPartEditor : System.Web.UI.WebControls.WebParts.EditorPart
    {
        DropDownList ddl;
        Panel toolPartPanel;
        TextBox tb;

        protected override void CreateChildControls()
        {
            toolPartPanel = new Panel();
            ddl = new DropDownList();
            ddl.ID = "ddl";

            // Simply getting the lists of the current web, and displaying them in the dropdown-list.
            SPListCollection lists = SPContext.Current.Web.Lists;
            foreach (SPList list in lists)
                ddl.Items.Add(list.Title);

            tb = new TextBox();
            tb.ID = "tb";

            toolPartPanel.Controls.Add(ddl);
            toolPartPanel.Controls.Add(tb);
            Controls.Add(toolPartPanel);
            base.CreateChildControls();
        }
        public ListQueryWebPartEditor(string webpartID)
        {
            this.ID = String.Format("BannerEditor{0}", webpartID);
            this.Title = webpartID;
        }
        public override bool ApplyChanges()
        {
            EnsureChildControls();
            ListQueryWebPart wp = WebPartToEdit as ListQueryWebPart;
            wp.Property1 = ddl.SelectedValue;
            wp.Property2 = tb.Text;
            return true;
        }
        public override void SyncChanges()
        {
            EnsureChildControls();
            ListQueryWebPart wp = WebPartToEdit as ListQueryWebPart;
            ddl.SelectedValue = wp.Property1;
            tb.Text = wp.Property2;
        } 
    }
    
}
